package org.example.schoolbus.service.impl;
import org.example.schoolbus.mapper.RegisterMapper;
import org.example.schoolbus.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class RegisterServiceimpl implements RegisterService {
    @Autowired
    private RegisterMapper registerMapper;
    @Override
    public int checkUseUser(String username, String useremail, String userphone) {
        List<Map<String, Object>> list = registerMapper.checkUseUser(username, useremail, userphone);
        for (Map<String, Object> map : list) {
            if (map.get("username").equals(username)) {
                return 1; // 用户名被注册过
            } else if (map.get("useremail").equals(useremail)) {
                return 2; // 邮箱被注册过
            } else if (map.get("userphone").equals(userphone)) {
                return 3; // 电话号码被注册过
            }
        }
        return 0; // 没有冲突
    }
    @Override
    public int RegisterUser(String userstyle,String username,String useremail,String userphone,String userpassword)
    {
        if(registerMapper.RegisterUser(userstyle,username,useremail,userphone,userpassword)>0)
        {
            return 1;
        }
        else
            return 0;
    }

}
